<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
const props = defineProps<{
  title?: string
  rightText?: string
  back?: () => void
}>()

// 子传父
const emit = defineEmits<{
  (event: 'onClickLeft'): void
  (event: 'onClickRight'): void
}>()

const onClickLeft = () => {
  if (props.back) return props.back()
  // console.log('箭头')
  // 子传父
  // emit('onClickLeft')
  // 判断历史记录是否有back
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/')
  }
}
const onClickRight = () => {
  console.log('文字')
  emit('onClickRight')
}
</script>
<template>
  <van-nav-bar
    fixed
    :title="title"
    :right-text="rightText"
    left-arrow
    @click-left="onClickLeft"
    @click-right="onClickRight"
  />
</template>
<style scoped lang="scss">
// 修改组件内部样式添加组件穿透
:deep() {
  .van-nav-bar {
    &_arrow {
      color: var(-cp-text1);
      font-size: 18px;
    }
    &_title {
      font-size: 15px;
    }
  }
}
</style>
